#include "routines.h"
using namespace std;
/*
Cu = max(0; Su - K)
Cd = max(0; Sd - K)
C0 = e^-r (qCu + (1 - q)Cd)
q =
er- d
-----
u - d*/
double maxize(double a,double b){
	return a<b?b:a;
}
double option_price_call_european_binomial_single_period( const double& S, // spot price
														 const double& X, // exercise price
														 const double& r, // interest rate (per period)
														 const double& u, // up movement
														 const double& d){ // down movement
	double p_up = (exp(r)-d)/(u-d);
	double p_down = 1.0-p_up;
	double c_u = maxize(0.0,(u*S-X));
	double c_d = maxize(0.0,(d*S-X));
	double call_price = exp(-r)*(p_up*c_u+p_down*c_d);
	return call_price;
};

